<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>游戏开关设置</title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="icon" type="image/png" href="i/buyu.ico">
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet" href="layui/css/layui.css">
		<style>
		  .layui-form-item > .layui-input-block span {
		      font-size : 14px;
		      line-height : 14px;
		      display : inline-block;
		      margin-top : 8px;
		  }
		</style>
	</head>

	<body>
	  <br>
        <form class="layui-form">
          <div class="layui-form-item" lay-filter="ItemSwitch">
		      <div class="layui-input-block">
		        <span>大厅排行榜 </span>
		        <input  type="hidden" name="Rank" id="Rank" value="1">
		        <input type="checkbox" name="RankSwitch" id="RankSwitch" lay-skin="switch" lay-filter="RankSwitch" lay-text="开|关 ">
		      </div>
		      <div class="layui-input-block">
		        <span>大厅竞技场 </span>
		        <input  type="hidden" name="Arena" id="Arena" value="1">
		        <input type="checkbox" name="ArenaSwitch" id="ArenaSwitch" lay-skin="switch" lay-filter="ArenaSwitch" lay-text="开|关">
		      </div>
		  </div>
		  <div class="layui-form-item">
		   <div class="layui-input-block">
		     <button type="submit" class="layui-btn" lay-submit="" lay-filter="go" id="go">确认修改</button>
		     <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		   </div>
		 </div>
       </form>
       
       
       <form class="layui-form">
          <div class="layui-form-item">
		      <div class="layui-input-block">
		        <span>世界BOSS</span>
		        <input  type="hidden" name="FishBoss" id="FishBoss" value="1">
		        <input type="checkbox" name="FishBossSwitch" id="FishBossSwitch" lay-skin="switch" lay-filter="FishBossSwitch" lay-text="开|关 ">
		      </div>
		  </div>
		  <div class="layui-form-item">
		   <div class="layui-input-block">
		     <button type="submit" class="layui-btn" lay-submit="" lay-filter="fishgo" id="fishgo">确认修改</button>
		     <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		   </div>
		 </div>
       </form>
		

		<script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
        <script>
        layui.use(['layer','form'], function () {
            var layer = layui.layer, 
                form = layui.form;
            //DOM加载结束
            $(function(){
            	$.ajax({
            		url : 'game/switchfishgetting',
            		type : 'POST',
            		async : true,
            		success : function(resp) {
            			resp = JSON.parse(resp);
            			for(var key in resp) {
            				if(resp[key] === '0'){
            					$("input[type=checkbox][name=" + key + "]")[0].checked = true;
            					
            				}
            				else if(resp[key] === '1'){
            					$("input[type=checkbox][name=" + key + "]")[0].checked = false;
            				}else{
            					
            				}
            			}
            		form.render('checkbox');
            		}
            	});
            });
            
            form.on('switch(RankSwitch)',function(data){
            	if (data.elem.checked === false) {
            		//这是关操作
            		$("input[type=hidden][name=Rank]").val('1');
            	}else {
            		//这是开操作
            		$("input[type=hidden][name=Rank]").val('0');
            	}
            })
            
            
            form.on('switch(ArenaSwitch)',function(data){
            	if (data.elem.checked === false) {
            		//这是关操作
            		$("input[type=hidden][name=Arena]").val('1');
            	}else {
            		//这是开操作
            		$("input[type=hidden][name=Arena]").val('0');
            	}
            })
            
            form.on('switch(FishBossSwitch)',function(data){
            	if (data.elem.checked === false) {
            		//这是关操作
            		$("input[type=hidden][name=FishBoss]").val('1');
            	}else {
            		//这是开操作
            		$("input[type=hidden][name=FishBoss]").val('0');
            	}
            })
            form.on('submit(go)', function (data) {
            	var loadingIndex = layer.msg('提交中..', {
    			    icon: 16
    			    ,shade: 0.3
    			    ,time: false
    			});
            	$.ajax({
            		type:'post',
            		url:"game/switchsetting",
            		data:{
            			Rank: $("input[type=hidden][name=Rank]").val(),
            			Arena: $("input[type=hidden][name=Arena]").val()
            		},
            		success:function(data){
            			layer.close(loadingIndex);
	            	    if(data == "success"){
	            			layer.msg("发布成功",{icon:1});
            			}else{
            				layer.msg(data,{icon:2});
            			}
            		},error:function(){
            			layer.msg("发布失败");
            		}
            	});
              return false;
            });
            
            form.on('submit(fishgo)', function (data) {
            	var loadingIndex = layer.msg('提交中..', {
    			    icon: 16
    			    ,shade: 0.3
    			    ,time: false
    			});
            	$.ajax({
            		type:'post',
            		url:"game/switchfishsetting",
            		data:{
            			IsFishBossClose: $("input[type=hidden][name=FishBoss]").val()
            		},
            		success:function(data){
            			layer.close(loadingIndex);
	            	    if(data == "success"){
	            			layer.msg("发布成功",{icon:1});
            			}else{
            				layer.msg(data,{icon:2});
            			}
            		},error:function(){
            			layer.msg("发布失败");
            		}
            	});
              return false;
            });
            });
        </script>
	</body>

</html>
